<?php
namespace app\index\model;

use think\Model;

/**
* 职位管理
*/
class Job extends Model
{
	public function getCidAttr($value)
    {	
    	$name = db('company')->where('id='.$value)->value('name');
        return $name;
    }
    public function getUpdateTimeAttr($value)
    {	
    	return $this->format_date($value);
    }

    public function getTypeAttr($value)
    {
    	$arr = [0=>'兼职',1=>'全职'];
    	return $arr[$value];
    }
    public function getIsShowAttr($value)
    {
        $arr = [0=>'已下线',1=>'发布中'];
        return $arr[$value];
    }

    function format_date($time){
    	$t=time()-strtotime($time);
    	$f=array(
	        '31536000'=>'年',
	        '2592000'=>'个月',
	        '604800'=>'星期',
	        '86400'=>'天',
	        '3600'=>'小时',
	        '60'=>'分钟',
	        '1'=>'秒'
    	);
    	foreach ($f as $k=>$v)    {
        	if (0 !=$c=floor($t/(int)$k)) {
            	return $c.$v.'前';
        	}
    	}
    }

}